<?php
/**
 * 产品配置信息
 *
 * @author xiemaomao@iwgame.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Product.php 1052 2011-11-16 06:09:20Z mmxie $
 */
class IG_Product_Config_Product extends IG_Product_Config_Abstract
{
    protected $_areas  = array();
    protected $_groups = array();

    public function __construct($data = null)
    {
        parent::__construct($data);
        if (!isset($this->_data['children'])) return ;
        foreach ($this->_data['children'] as $item) {
            if (strpos($item['tags'], 'game-area') !== false) {
                $this->_areas[$item['name']] = new IG_Product_Config_Area($item);
            } else if (strpos($item['tags'], 'game-group') !== false) {
                $this->_groups[$item['name']] = new IG_Product_Config_Group($item);
            }
        }
    }

    /**
     * @return IG_Product_Config_Area
     */
    public function getArea($name)
    {
        return isset($this->_areas[$name]) ?
                $this->_areas[$name] : new IG_Product_Config_Area;
    }

    public function getAreas()
    {
        return $this->_areas;
    }

    /**
     * @return IG_Product_Config_Group
     */
    public function getGroup($name)
    {
        return isset($this->_groups[$name]) ?
                $this->_groups[$name] : new IG_Product_Config_Group;
    }

    public function getGroups()
    {
        if (empty($this->_groups)) {
            $groups = array();
            foreach ($this->getAreas() as $area) {
                $groups = array_merge($groups, $area->getGroups());
            }
            $this->_groups = $groups;;
        }

        return $this->_groups;
    }
}